<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>objectmatcher.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_labs_testing_objectmatcher.js.html">objectmatcher.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Provides the built-in object matchers like equalsObject,
<a name="line17"></a> *     hasProperty, instanceOf, etc.
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.labs.testing.HasPropertyMatcher&#39;);
<a name="line23"></a>goog.provide(&#39;goog.labs.testing.InstanceOfMatcher&#39;);
<a name="line24"></a>goog.provide(&#39;goog.labs.testing.IsNullMatcher&#39;);
<a name="line25"></a>goog.provide(&#39;goog.labs.testing.IsNullOrUndefinedMatcher&#39;);
<a name="line26"></a>goog.provide(&#39;goog.labs.testing.IsUndefinedMatcher&#39;);
<a name="line27"></a>goog.provide(&#39;goog.labs.testing.ObjectEqualsMatcher&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>goog.require(&#39;goog.labs.testing.Matcher&#39;);
<a name="line31"></a>goog.require(&#39;goog.string&#39;);
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * The Equals matcher.
<a name="line37"></a> *
<a name="line38"></a> * @param {!Object} expectedObject The expected object.
<a name="line39"></a> *
<a name="line40"></a> * @constructor
<a name="line41"></a> * @implements {goog.labs.testing.Matcher}
<a name="line42"></a> */
<a name="line43"></a>goog.labs.testing.ObjectEqualsMatcher = function(expectedObject) {
<a name="line44"></a>  /**
<a name="line45"></a>   * @type {!Object}
<a name="line46"></a>   * @private
<a name="line47"></a>   */
<a name="line48"></a>  this.object_ = expectedObject;
<a name="line49"></a>};
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>/**
<a name="line53"></a> * Determines if two objects are the same.
<a name="line54"></a> *
<a name="line55"></a> * @override
<a name="line56"></a> */
<a name="line57"></a>goog.labs.testing.ObjectEqualsMatcher.prototype.matches =
<a name="line58"></a>    function(actualObject) {
<a name="line59"></a>  return actualObject === this.object_;
<a name="line60"></a>};
<a name="line61"></a>
<a name="line62"></a>
<a name="line63"></a>/**
<a name="line64"></a> * @override
<a name="line65"></a> */
<a name="line66"></a>goog.labs.testing.ObjectEqualsMatcher.prototype.describe =
<a name="line67"></a>    function(actualObject) {
<a name="line68"></a>  return &#39;Input object is not the same as the expected object.&#39;;
<a name="line69"></a>};
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>
<a name="line73"></a>/**
<a name="line74"></a> * The HasProperty matcher.
<a name="line75"></a> *
<a name="line76"></a> * @param {string} property Name of the property to test.
<a name="line77"></a> *
<a name="line78"></a> * @constructor
<a name="line79"></a> * @implements {goog.labs.testing.Matcher}
<a name="line80"></a> */
<a name="line81"></a>goog.labs.testing.HasPropertyMatcher = function(property) {
<a name="line82"></a>  /**
<a name="line83"></a>   * @type {string}
<a name="line84"></a>   * @private
<a name="line85"></a>   */
<a name="line86"></a>  this.property_ = property;
<a name="line87"></a>};
<a name="line88"></a>
<a name="line89"></a>
<a name="line90"></a>/**
<a name="line91"></a> * Determines if an object has a property.
<a name="line92"></a> *
<a name="line93"></a> * @override
<a name="line94"></a> */
<a name="line95"></a>goog.labs.testing.HasPropertyMatcher.prototype.matches =
<a name="line96"></a>    function(actualObject) {
<a name="line97"></a>  return this.property_ in actualObject;
<a name="line98"></a>};
<a name="line99"></a>
<a name="line100"></a>
<a name="line101"></a>/**
<a name="line102"></a> * @override
<a name="line103"></a> */
<a name="line104"></a>goog.labs.testing.HasPropertyMatcher.prototype.describe =
<a name="line105"></a>    function(actualObject) {
<a name="line106"></a>  return &#39;Object does not have property: &#39; + this.property_;
<a name="line107"></a>};
<a name="line108"></a>
<a name="line109"></a>
<a name="line110"></a>
<a name="line111"></a>/**
<a name="line112"></a> * The InstanceOf matcher.
<a name="line113"></a> *
<a name="line114"></a> * @param {!Object} object The expected class object.
<a name="line115"></a> *
<a name="line116"></a> * @constructor
<a name="line117"></a> * @implements {goog.labs.testing.Matcher}
<a name="line118"></a> */
<a name="line119"></a>goog.labs.testing.InstanceOfMatcher = function(object) {
<a name="line120"></a>  /**
<a name="line121"></a>   * @type {!Object}
<a name="line122"></a>   * @private
<a name="line123"></a>   */
<a name="line124"></a>  this.object_ = object;
<a name="line125"></a>};
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/**
<a name="line129"></a> * Determines if an object is an instance of another object.
<a name="line130"></a> *
<a name="line131"></a> * @override
<a name="line132"></a> */
<a name="line133"></a>goog.labs.testing.InstanceOfMatcher.prototype.matches =
<a name="line134"></a>    function(actualObject) {
<a name="line135"></a>  return actualObject instanceof this.object_;
<a name="line136"></a>};
<a name="line137"></a>
<a name="line138"></a>
<a name="line139"></a>/**
<a name="line140"></a> * @override
<a name="line141"></a> */
<a name="line142"></a>goog.labs.testing.InstanceOfMatcher.prototype.describe =
<a name="line143"></a>    function(actualObject) {
<a name="line144"></a>  return &#39;Input object is not an instance of the expected object&#39;;
<a name="line145"></a>};
<a name="line146"></a>
<a name="line147"></a>
<a name="line148"></a>
<a name="line149"></a>/**
<a name="line150"></a> * The IsNullOrUndefined matcher.
<a name="line151"></a> *
<a name="line152"></a> * @constructor
<a name="line153"></a> * @implements {goog.labs.testing.Matcher}
<a name="line154"></a> */
<a name="line155"></a>goog.labs.testing.IsNullOrUndefinedMatcher = function() {};
<a name="line156"></a>
<a name="line157"></a>
<a name="line158"></a>/**
<a name="line159"></a> * Determines if input value is null or undefined.
<a name="line160"></a> *
<a name="line161"></a> * @override
<a name="line162"></a> */
<a name="line163"></a>goog.labs.testing.IsNullOrUndefinedMatcher.prototype.matches =
<a name="line164"></a>    function(actualValue) {
<a name="line165"></a>  return !goog.isDefAndNotNull(actualValue);
<a name="line166"></a>};
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/**
<a name="line170"></a> * @override
<a name="line171"></a> */
<a name="line172"></a>goog.labs.testing.IsNullOrUndefinedMatcher.prototype.describe =
<a name="line173"></a>    function(actualValue) {
<a name="line174"></a>  return actualValue + &#39; is not null or undefined.&#39;;
<a name="line175"></a>};
<a name="line176"></a>
<a name="line177"></a>
<a name="line178"></a>
<a name="line179"></a>/**
<a name="line180"></a> * The IsNull matcher.
<a name="line181"></a> *
<a name="line182"></a> * @constructor
<a name="line183"></a> * @implements {goog.labs.testing.Matcher}
<a name="line184"></a> */
<a name="line185"></a>goog.labs.testing.IsNullMatcher = function() {};
<a name="line186"></a>
<a name="line187"></a>
<a name="line188"></a>/**
<a name="line189"></a> * Determines if input value is null.
<a name="line190"></a> *
<a name="line191"></a> * @override
<a name="line192"></a> */
<a name="line193"></a>goog.labs.testing.IsNullMatcher.prototype.matches =
<a name="line194"></a>    function(actualValue) {
<a name="line195"></a>  return goog.isNull(actualValue);
<a name="line196"></a>};
<a name="line197"></a>
<a name="line198"></a>
<a name="line199"></a>/**
<a name="line200"></a> * @override
<a name="line201"></a> */
<a name="line202"></a>goog.labs.testing.IsNullMatcher.prototype.describe =
<a name="line203"></a>    function(actualValue) {
<a name="line204"></a>  return actualValue + &#39; is not null.&#39;;
<a name="line205"></a>};
<a name="line206"></a>
<a name="line207"></a>
<a name="line208"></a>
<a name="line209"></a>/**
<a name="line210"></a> * The IsUndefined matcher.
<a name="line211"></a> *
<a name="line212"></a> * @constructor
<a name="line213"></a> * @implements {goog.labs.testing.Matcher}
<a name="line214"></a> */
<a name="line215"></a>goog.labs.testing.IsUndefinedMatcher = function() {};
<a name="line216"></a>
<a name="line217"></a>
<a name="line218"></a>/**
<a name="line219"></a> * Determines if input value is undefined.
<a name="line220"></a> *
<a name="line221"></a> * @override
<a name="line222"></a> */
<a name="line223"></a>goog.labs.testing.IsUndefinedMatcher.prototype.matches =
<a name="line224"></a>    function(actualValue) {
<a name="line225"></a>  return !goog.isDef(actualValue);
<a name="line226"></a>};
<a name="line227"></a>
<a name="line228"></a>
<a name="line229"></a>/**
<a name="line230"></a> * @override
<a name="line231"></a> */
<a name="line232"></a>goog.labs.testing.IsUndefinedMatcher.prototype.describe =
<a name="line233"></a>    function(actualValue) {
<a name="line234"></a>  return actualValue + &#39; is not undefined.&#39;;
<a name="line235"></a>};
<a name="line236"></a>
<a name="line237"></a>
<a name="line238"></a>/**
<a name="line239"></a> * Returns a matcher that matches objects that are equal to the input object.
<a name="line240"></a> * Equality in this case means the two objects are references to the same
<a name="line241"></a> * object.
<a name="line242"></a> *
<a name="line243"></a> * @param {!Object} object The expected object.
<a name="line244"></a> *
<a name="line245"></a> * @return {!goog.labs.testing.ObjectEqualsMatcher} A
<a name="line246"></a> *     ObjectEqualsMatcher.
<a name="line247"></a> */
<a name="line248"></a>function equalsObject(object) {
<a name="line249"></a>  return new goog.labs.testing.ObjectEqualsMatcher(object);
<a name="line250"></a>}
<a name="line251"></a>
<a name="line252"></a>
<a name="line253"></a>/**
<a name="line254"></a> * Returns a matcher that matches objects that contain the input property.
<a name="line255"></a> *
<a name="line256"></a> * @param {string} property The property name to check.
<a name="line257"></a> *
<a name="line258"></a> * @return {!goog.labs.testing.HasPropertyMatcher} A HasPropertyMatcher.
<a name="line259"></a> */
<a name="line260"></a>function hasProperty(property) {
<a name="line261"></a>  return new goog.labs.testing.HasPropertyMatcher(property);
<a name="line262"></a>}
<a name="line263"></a>
<a name="line264"></a>
<a name="line265"></a>/**
<a name="line266"></a> * Returns a matcher that matches instances of the input class.
<a name="line267"></a> *
<a name="line268"></a> * @param {!Object} object The class object.
<a name="line269"></a> *
<a name="line270"></a> * @return {!goog.labs.testing.InstanceOfMatcher} A
<a name="line271"></a> *     InstanceOfMatcher.
<a name="line272"></a> */
<a name="line273"></a>function instanceOfClass(object) {
<a name="line274"></a>  return new goog.labs.testing.InstanceOfMatcher(object);
<a name="line275"></a>}
<a name="line276"></a>
<a name="line277"></a>
<a name="line278"></a>/**
<a name="line279"></a> * Returns a matcher that matches all null values.
<a name="line280"></a> *
<a name="line281"></a> * @return {!goog.labs.testing.IsNullMatcher} A IsNullMatcher.
<a name="line282"></a> */
<a name="line283"></a>function isNull() {
<a name="line284"></a>  return new goog.labs.testing.IsNullMatcher();
<a name="line285"></a>}
<a name="line286"></a>
<a name="line287"></a>
<a name="line288"></a>/**
<a name="line289"></a> * Returns a matcher that matches all null and undefined values.
<a name="line290"></a> *
<a name="line291"></a> * @return {!goog.labs.testing.IsNullOrUndefinedMatcher} A
<a name="line292"></a> *     IsNullOrUndefinedMatcher.
<a name="line293"></a> */
<a name="line294"></a>function isNullOrUndefined() {
<a name="line295"></a>  return new goog.labs.testing.IsNullOrUndefinedMatcher();
<a name="line296"></a>}
<a name="line297"></a>
<a name="line298"></a>
<a name="line299"></a>/**
<a name="line300"></a> * Returns a matcher that matches undefined values.
<a name="line301"></a> *
<a name="line302"></a> * @return {!goog.labs.testing.IsUndefinedMatcher} A IsUndefinedMatcher.
<a name="line303"></a> */
<a name="line304"></a>function isUndefined() {
<a name="line305"></a>  return new goog.labs.testing.IsUndefinedMatcher();
<a name="line306"></a>}
</pre>


</body>
</html>
